// @charset "utf-8";

define(function(require, exports, module) {
	var publicMethod = require('../../public/public'),
		clientApi = require('../../public/clientapi'),
		clientStorage = require('../../public/storage');

	var IndexBase = require('../allindex/indexbase');
	var indexBase = new IndexBase();

	var hsgtModel = require('../hsgtzj/model');
	// var modulesInit = require('../init');
	var dataStore = require('../../control/datastore');

	var renderComChart = function(score) {
		var scoreText;
		var dpglColors = ['#4c4c4c', '#4c4c4c'];
		var dpglData = [0, 10];
		var tipText = '';
		if (score != '--') {
			score = parseFloat(score);
			scoreText = score.toFixed(1);
			if (score < 4) {
				dpglColors = ['#72b410', '#4c4c4c'];
				tipText = '短期大盘趋势弱，增量资金入场不明显，市场赚钱效应弱';
				$('.overall-text').addClass('overall-text-show');
			} else if (score >= 4 && score < 6) {
				dpglColors = ['#fac550', '#4c4c4c'];
				tipText = '短期大盘趋势偏弱，增量资金入场未见明显，市场赚钱效应偏弱';
				$('.overall-text').addClass('overall-text-show');
			} else if (score >= 6 && score < 8) {
				dpglColors = ['#ffad00', '#4c4c4c'];
				tipText = '短期大盘趋势偏强，增量资金入场较明显，市场赚钱效应偏强';
				$('.overall-text').removeClass('overall-text-show');
			} else if (score >= 8) {
				dpglColors = ['#e62e2e', '#4c4c4c'];
				tipText = '短期大盘趋势强，增量资金入场明显，市场赚钱效应强';
				$('.overall-text').removeClass('overall-text-show');
			}
			dpglData = [score, 10 - score];
		} else {
			scoreText = '--';
		}
		$('.overall-text p').text(tipText);
		var chartTitle = '<span class="zhqd-title">综合强度<br/><strong>' + scoreText + '</strong></span>';
		$('.overall-chart').highcharts({
			chart: {
				type: 'pie',
				backgroundColor: 'rgba(0,0,0,.0)',
				plotShadow: false,
				events: {
					click: function() {
						$('.switch-panel').addClass('hide');
						$('.btn-interval').addClass('hide');
					}
				}
			},
			credits: {
				text: ''
			},
			title: {
				text: chartTitle,
				verticalAlign: 'middle',
				useHTML: true,
				y: -6
			},
			tooltip: {
				enabled: false,
				backgroundColor: "#000",
				style: {
					color: "#fff"
				},
				userHTML: true,
				formatter: function() {
					return '<p>' + this.key + ':' + this.y + '</p>';
				}
			},
			plotOptions: {
				pie: {
					size: 114,
					borderWidth: 0,
					innerSize: 84,
					colors: dpglColors,
					borderColor: '#252525',
					dataLabels: {
						enabled: false
					}
				}
			},
			series: [{
				startAngle: 315,
				data: dpglData,
				states: {
					hover: {
						enabled: false
					}
				}
			}]
		});
	};
	var overallModule = {
		domId: 'overall',
		init: function() {
			var self = this;

			self.renderDom();
			setTimeout(function() {
				self.refresh();
			}, 1500);

			self.events();
		},
		renderDom: function () {
			var self = this;
			var htmlDom = '<li data-mname="'+ self.domId +'">' +
					'<div class="module-item">' +
						'<div class="module-header">' +
							'<a href="###" class="icon module-close-btn"></a>' +
							'<p class="module-name">综合概述</p>' +
						'</div>' +
						'<div class="module-main clearfix module-overall">' +
							'<div class="overall-left">' +
								'<div class="overall-chart">' +
								'</div>' +
								'<!-- TODO: is show icon class> overall-text-show -->' +
								'<div class="overall-text">' +
									'<i></i>' +
									'<p></p>' +
								'</div>' +
							'</div>' +
							'<div class="overall-right">' +
								'<div class="section-item sec-item1 scqr_wrap">' +
									'<span class="section-name">市场强弱：</span>' +
									'<div class="progress-bg">' +
										'<p class="progress-bar">' +
										'<span class="progress-score" data-group-score="0">--</span>' +
										'</p>' +
									'</div>' +
									'<div class="level-panel hide">' +
										'<div class="level-item">' +
											'<p class="level-name">强弱评级</p>' +
											'<p class="level-data">涨跌停比 <i class="red v_d_qrpj1">--</i> / <i class="green v_d_qrpj2">--</i></p>' +
											'<b class="level-star star-level0 v_s_qrpj" data-rating="0"></b>' +
										'</div>' +
										'<div class="level-item">' +
											'<p class="level-name">封板率</p>' +
											'<p class="level-data">封板成功率 <i class="v_d_fbl">--</i></p>' +
											'<b class="level-star star-level0 v_s_fbl" data-rating="0"></b>' +
										'</div>' +
										'<div class="level-item">' +
											'<p class="level-name">涨跌统计</p>' +
											'<p class="level-data">涨幅大于5%个股 <i class="red v_d_zdtj">--</i></p>' +
											'<b class="level-star star-level0 v_s_zdtj" data-rating="0"></b>' +
										'</div>' +
									'</div>' +
								'</div>' +
								'<div class="section-item sec-item2 zjdt_wrap">' +
									'<span class="section-name">资金动态：</span>' +
									'<div class="progress-bg">' +
										'<p class="progress-bar">' +
										'<span class="progress-score" data-group-score="0">--</span>' +
										'</p>' +
									'</div>' +
									'<div class="level-panel hide">' +
										'<div class="level-item">' +
											'<p class="level-name">融资融券</p>' +
											'<p class="level-data">3日融资余额增速比例 <i class="v_d_rzrq">--</i></p>' +
											'<b class="level-star star-level0 v_s_rzrq" data-rating="0"></b>' +
										'</div>' +
										'<div class="level-item">' +
											'<p class="level-name">沪股通资金</p>' +
											'<p class="level-data"><span class="hMoneyflow">资金流向</span> <i class="v_d_hgtzj"></i></p>' +
											'<b class="level-star star-level0 v_s_hgtzj" data-rating="0"></b>' +
										'</div>' +
										'<div class="level-item">' +
											'<p class="level-name">深股通资金</p>' +
											'<p class="level-data"><span class="sMoneyflow">资金流向</span> <i class="v_d_sgtzj"></i></p>' +
											'<b class="level-star star-level0 v_s_sgtzj" data-rating="0"></b>' +
										'</div>' +
									'</div>' +
								'</div>' +
								'<div class="section-item sec-item3 zqxy_wrap">' +
									'<span class="section-name">赚钱效应：</span>' +
									'<div class="progress-bg">' +
										'<p class="progress-bar">' +
										'<span class="progress-score" data-group-score="0">--</span>' +
										'</p>' +
									'</div>' +
									'<div class="level-panel hide">' +
										'<div class="level-item">' +
											'<p class="level-name">赚钱效应</p>' +
											'<p class="level-data">昨日涨停表现 <i class="v_d_zqxy">--</i></p>' +
											'<b class="level-star star-level0 v_s_zqxy" data-rating="0"></b>' +
										'</div>' +
										'<div class="level-item">' +
											'<p class="level-name">昨日自选50</p>' +
											'<p class="level-data">昨日自选50股表现 <i class="v_d_zrzx">--</i></p>' +
											'<b class="level-star star-level0 v_s_zrzx" data-rating="0"></b>' +
										'</div>' +
										'<div class="level-item">' +
											'<p class="level-name">昨日热门100</p>' +
											'<p class="level-data">昨日热门100股表现 <i class="v_d_zrrm">--</i></p>' +
											'<b class="level-star star-level0 v_s_zrrm" data-rating="0"></b>' +
										'</div>' +
									'</div>' +
								'</div>' +
							'</div>' +
						'</div>' +
					'</div>' +
				'</li>';
			$('#modules-list-ul').append(htmlDom);
		},
		refresh: async function() {
			var self = this;
			var tradeDay = await clientApi.getTradingDay();
			// 强弱评级
			publicMethod.ajaxJsonp({
				url: 'http://hqstats.10jqka.com.cn/fyzzt.php?date=' + tradeDay,
				jsonpCallback: 'fyzzt',
				callback: function(result) {
					var ztData = [],
						dtData = [],
						ztNewestData = '--',
						dtNewestData = '--';
					if (!$.isEmptyObject(result)) {
						$.each(result.data, function(i, val) {
							ztData.push(val.zt);
							dtData.push(val.dt);
						});

						ztNewestData = ztData[ztData.length - 1];
						dtNewestData = dtData[dtData.length - 1];
					}
					self.renderQrpjStar(ztNewestData, dtNewestData);
					self.calcComScore('scqr');
					dataStore.autoRenderPlate('qrpjModule', tradeDay, result);
				}
			});

			// 封板率
			publicMethod.ajaxJson({
				url: publicMethod.urlList.fblUrl,
				callback: function(result) {
					// alert(JSON.stringify(result));
					var fbl = '--';
					if (result) {
						fbl = parseFloat(result.data.jrfb * 100).toFixed(1);
					}
					self.renderFblStar(fbl);
					self.calcComScore('scqr');
				}
			});

			// 涨跌统计
			publicMethod.ajaxJsonp({
				url: publicMethod.urlList.zdtjUrl,
				data: {
					date: tradeDay
				},
				jsonpCallback: 'zhangfustats',
				callback: function(result) {
					var data5 = '--';
					if (result && result.length > 0) {
						data5 = result[0] + result[1] + result[2] + result[3] + result[4];
					}
					self.renderZdtjStar(data5);
					self.calcComScore('scqr');
					dataStore.autoRenderPlate('zdtjModule', tradeDay, result);
				}
			});

			// 赚钱效应
			indexBase.requestMin('883900,1A0001', tradeDay, function(result) {
				var dataLen = result['883900'].length;
				var data = '--';
				if (dataLen > 0) {
					data = result['883900'][dataLen - 1];
				}
				self.renderZqxyStar(data);
				self.calcComScore('zqxy');
				dataStore.autoRenderPlate('zqxyModule', tradeDay, result);
			});

			// 自选50
			indexBase.requestMin('883909,1A0001', tradeDay, function(result) {
				var dataLen = result['883909'].length;
				var data = '--';
				if (dataLen > 0) {
					data = result['883909'][dataLen - 1];
				}
				self.renderZrzxStar(data);
				self.calcComScore('zqxy');
				dataStore.autoRenderPlate('zrzxModule', tradeDay, result);
			});

			// 昨日热门100
			indexBase.requestMin('883910,1A0001', tradeDay, function(result) {
				var dataLen = result['883910'].length;
				var data = '--';
				if (dataLen > 0) {
					data = result['883910'][dataLen - 1];
				}
				self.renderZrrmStar(data);
				self.calcComScore('zqxy');
				dataStore.autoRenderPlate('zrrmModule', tradeDay, result);
			});

			// 融资融券
			var preMonthDate = await clientApi.preMonthDate();
			var preDate = await clientApi.preDate();
			var url = 'zx/get_homepage_data.lua?op=rzyebd&begin_date=' + preMonthDate + '&end_date=' + preDate;
			var rzrqBool = clientApi.thsQuote.requestZxData({
				url: url,
				onready: function(res) {
					res = JSON.parse(res);
					var data = '--';
					if (res.length > 0) {
						data = res[res.length - 1]['rzzs'];
					}
					self.renderRzrqStar(parseFloat(data));
					self.calcComScore('zjdt');
				}
			});
			if (!rzrqBool) {}

			// 沪深股通资金流向
			var hgtBegin = '';
			hsgtModel.getIsTrading(tradeDay, function(result1) {
				if (result1 && result1.errorcode === 0) {

					var hgtRst = result1.result.hgt;
					hgtBegin = hgtRst.latesttradeday;

					hsgtModel.requestData(hgtBegin, false, function(result2) {
						result2 = result2[0];
						var hgtData = [],
							sgtData = [];

						var hgtNewData = result2.hgt.data[result2.hgt.data.length - 1]['value'];
						var sgtNewData = result2.sgt.data[result2.sgt.data.length - 1]['value'];
						// alert(hgtNewData + '----' + sgtNewData);
						self.renderHgtzjStar(hgtNewData);
						self.renderSgtzjStar(sgtNewData);
						self.calcComScore('zjdt');
					});

					dataStore.autoRenderPlate('hsgtzjModule', tradeDay, result1, result2);
				}
			});
		},
		renderHgtzjStar: function(data) {
			var gradeClass = 'star-level';
			var starLevel = 0;
			if (data <= -20) {
				starLevel = 1;
			} else if (data > -20 && data <= -15) {
				starLevel = 2;
			} else if (data > -15 && data <= -10) {
				starLevel = 3;
			} else if (data > -10 && data <= -5) {
				starLevel = 4;
			} else if (data > -5 && data <= 0) {
				starLevel = 5;
			} else if (data > 0 && data <= 5) {
				starLevel = 6;
			} else if (data > 5 && data <= 10) {
				starLevel = 7;
			} else if (data > 10 && data <= 15) {
				starLevel = 8;
			} else if (data > 15 && data <= 20) {
				starLevel = 9;
			} else if (data > 20) {
				starLevel = 10;
			}
			gradeClass = gradeClass + starLevel;
			$('.v_d_hgtzj').removeClass('red green');
			if (data > 0) {
				$('.hMoneyflow').text('资金流入');
				$('.v_d_hgtzj').addClass('red');
			} else if (data < 0) {
				$('.hMoneyflow').text('资金流出');
				$('.v_d_hgtzj').addClass('green');
			}
			$('.v_s_hgtzj').attr('data-rating', starLevel);
			$('.v_d_hgtzj').text(data + '亿');
			$('.v_s_hgtzj').attr('class', function(i, cls) {
				return cls.replace(/star-level\d+/g, gradeClass);
			});
		},
		renderSgtzjStar: function(data) {
			var gradeClass = 'star-level';
			var starLevel = 0;
			if (data <= -20) {
				starLevel = 1;
			} else if (data > -20 && data <= -15) {
				starLevel = 2;
			} else if (data > -15 && data <= -10) {
				starLevel = 3;
			} else if (data > -10 && data <= -5) {
				starLevel = 4;
			} else if (data > -5 && data <= 0) {
				starLevel = 5;
			} else if (data > 0 && data <= 5) {
				starLevel = 6;
			} else if (data > 5 && data <= 10) {
				starLevel = 7;
			} else if (data > 10 && data <= 15) {
				starLevel = 8;
			} else if (data > 15 && data <= 20) {
				starLevel = 9;
			} else if (data > 20) {
				starLevel = 10;
			}
			gradeClass = gradeClass + starLevel;
			$('.v_d_sgtzj').removeClass('red green');
			if (data > 0) {
				$('.sMoneyflow').text('资金流入');
				$('.v_d_sgtzj').addClass('red');
			} else if (data < 0) {
				$('.sMoneyflow').text('资金流出');
				$('.v_d_sgtzj').addClass('green');
			}
			$('.v_s_sgtzj').attr('data-rating', starLevel);
			$('.v_d_sgtzj').text(data + '亿');
			$('.v_s_sgtzj').attr('class', function(i, cls) {
				return cls.replace(/star-level\d+/g, gradeClass);
			});
		},
		renderQrpjStar: function(data, falldata) {
			var gradeClass = 'star-level';
			var starLevel = 0;
			if (!isNaN(data) && !isNaN(falldata)) {
				if (data >= 0 && data <= 5) {
					starLevel = 1;
				}
				if (data > 5 && data <= 10) {
					starLevel = 2;
				}
				if (data > 10 && data <= 15) {
					starLevel = 3;
				}
				if (data > 15 && data <= 20) {
					starLevel = 4;
				}
				if (data > 20 && data <= 25) {
					starLevel = 5;
				}
				if (data > 25 && data <= 50) {
					starLevel = 6;
				}
				if (data > 50 && data <= 65) {
					starLevel = 7;
				}
				if (data > 65 && data <= 80) {
					starLevel = 8;
				}
				if (data > 80 && data <= 100) {
					starLevel = 9;
				}
				if (data > 100) {
					starLevel = 10;
				}
			}
			gradeClass = gradeClass + starLevel;
			$('.v_s_qrpj').attr('data-rating', starLevel);
			$('.v_s_qrpj').attr('class', function(i, cls) {
				return cls.replace(/star-level\d+/g, gradeClass);
			});
			$('.v_d_qrpj1').text(data);
			$('.v_d_qrpj2').text(falldata);
		},
		renderFblStar: function(data) {
			var gradeClass = 'star-level';
			var starLevel = 0;
			if (!isNaN(data)) {
				if (data <= 10) {
					starLevel = 1;
				}
				if (data > 10 && data <= 15) {
					starLevel = 2;
				}
				if (data > 15 && data <= 20) {
					starLevel = 3;
				}
				if (data > 20 && data <= 25) {
					starLevel = 4;
				}
				if (data > 25 && data <= 35) {
					starLevel = 5;
				}
				if (data > 35 && data <= 40) {
					starLevel = 6;
				}
				if (data > 40 && data <= 50) {
					starLevel = 7;
				}
				if (data > 50 && data <= 60) {
					starLevel = 8;
				}
				if (data > 60 && data <= 80) {
					starLevel = 9;
				}
				if (data > 80) {
					starLevel = 10;
				}

				$('.v_d_fbl').text(data + '%');
			} else {
				$('.v_d_fbl').text('--');
			}
			gradeClass = gradeClass + starLevel;
			$('.v_s_fbl').attr('data-rating', starLevel);
			$('.v_s_fbl').attr('class', function(i, cls) {
				return cls.replace(/star-level\d+/g, gradeClass);
			});

		},
		renderZdtjStar: function(data) {
			var gradeClass = 'star-level';
			var starLevel = 0;

			$('.v_d_fbl').removeClass('red green');
			if (data != '--') {
				if (data > 0 && data <= 25) {
					starLevel = 1;
				} else if (data > 25 && data <= 40) {
					starLevel = 2;
				} else if (data > 40 && data <= 60) {
					starLevel = 3;
				} else if (data > 60 && data <= 80) {
					starLevel = 4;
				} else if (data > 80 && data <= 120) {
					starLevel = 5;
				} else if (data > 120 && data <= 150) {
					starLevel = 6;
				} else if (data > 150 && data <= 220) {
					starLevel = 7;
				} else if (data > 220 && data <= 300) {
					starLevel = 8;
				} else if (data > 300 && data <= 500) {
					starLevel = 9;
				} else if (data > 500) {
					starLevel = 10;
				}
				if (data > 50) {
					$('.v_d_fbl').addClass('red');
				} else {
					$('.v_d_fbl').addClass('green');
				}
			}
			gradeClass = gradeClass + starLevel;
			$('.v_d_zdtj').text(data);
			$('.v_s_zdtj').attr('data-rating', starLevel);
			$('.v_s_zdtj').attr('class', function(i, cls) {
				return cls.replace(/star-level\d+/g, gradeClass);
			});
		},
		renderZqxyStar: function(data) {
			var gradeClass = 'star-level';
			var starLevel = 0;
			$('.v_d_zqxy').removeClass('red green');

			if (!isNaN(data)) {
				if (data <= -0.5) {
					starLevel = 1;
				} else if (data > -0.5 && data <= 0.5) {
					starLevel = 2;
				} else if (data > 0.5 && data <= 1) {
					starLevel = 3;
				} else if (data > 1 && data <= 1.5) {
					starLevel = 4;
				} else if (data > 1.5 && data <= 2) {
					starLevel = 5;
				} else if (data > 2 && data <= 2.5) {
					starLevel = 6;
				} else if (data > 2.5 && data <= 3) {
					starLevel = 7;
				} else if (data > 3 && data <= 4) {
					starLevel = 8;
				} else if (data > 4 && data <= 6) {
					starLevel = 9;
				} else if (data > 6 && data <= 10) {
					starLevel = 10;
				}
				$('.v_d_zqxy').text(data + '%');
				if (data > 0) {
					$('.v_d_zqxy').addClass('red');
				} else if (data < 0) {
					$('.v_d_zqxy').addClass('green');
				}
			} else {
				$('.v_d_zqxy').text('--');
			}
			gradeClass = gradeClass + starLevel;
			$('.v_s_zqxy').attr('data-rating', starLevel);
			$('.v_s_zqxy').attr('class', function(i, cls) {
				return cls.replace(/star-level\d+/g, gradeClass);
			});

		},
		renderZrzxStar: function(data) {
			var gradeClass = 'star-level';
			var starLevel = 0;
			$('.v_d_zrzx').removeClass('red green');

			if (!isNaN(data)) {
				if (data <= -0.5) {
					starLevel = 1;
				} else if (data > -0.5 && data <= 0.5) {
					starLevel = 2;
				} else if (data > 0.5 && data <= 1) {
					starLevel = 3;
				} else if (data > 1 && data <= 1.5) {
					starLevel = 4;
				} else if (data > 1.5 && data <= 2) {
					starLevel = 5;
				} else if (data > 2 && data <= 2.5) {
					starLevel = 6;
				} else if (data > 2.5 && data <= 3) {
					starLevel = 7;
				} else if (data > 3 && data <= 4) {
					starLevel = 8;
				} else if (data > 4 && data <= 6) {
					starLevel = 9;
				} else if (data > 6 && data <= 10) {
					starLevel = 10;
				}
				$('.v_d_zrzx').text(data + '%');
				if (data > 0) {
					$('.v_d_zrzx').addClass('red');
				} else if (data < 0) {
					$('.v_d_zrzx').addClass('green');
				}
			} else {
				$('.v_d_zrzx').text('--');
			}
			gradeClass = gradeClass + starLevel;
			$('.v_s_zrzx').attr('data-rating', starLevel);
			$('.v_s_zrzx').attr('class', function(i, cls) {
				return cls.replace(/star-level\d+/g, gradeClass);
			});
		},
		renderZrrmStar: function(data) {
			var gradeClass = 'star-level';
			var starLevel = 0;
			$('.v_d_zrrm').removeClass('red green');

			if (!isNaN(data)) {
				if (data <= -0.5) {
					starLevel = 1;
				} else if (data > -0.5 && data <= 0.5) {
					starLevel = 2;
				} else if (data > 0.5 && data <= 1) {
					starLevel = 3;
				} else if (data > 1 && data <= 1.5) {
					starLevel = 4;
				} else if (data > 1.5 && data <= 2) {
					starLevel = 5;
				} else if (data > 2 && data <= 2.5) {
					starLevel = 6;
				} else if (data > 2.5 && data <= 3) {
					starLevel = 7;
				} else if (data > 3 && data <= 4) {
					starLevel = 8;
				} else if (data > 4 && data <= 6) {
					starLevel = 9;
				} else if (data > 6 && data <= 10) {
					starLevel = 10;
				}
				$('.v_d_zrrm').text(data + '%');
				if (data > 0) {
					$('.v_d_zrrm').addClass('red');
				} else if (data < 0) {
					$('.v_d_zrrm').addClass('green');
				}
			} else {
				$('.v_d_zrrm').text('--');
			}
			gradeClass = gradeClass + starLevel;
			$('.v_s_zrrm').attr('data-rating', starLevel);
			$('.v_s_zrrm').attr('class', function(i, cls) {
				return cls.replace(/star-level\d+/g, gradeClass);
			});
		},
		renderRzrqStar: function(data) {
			var gradeClass = 'star-level';
			var starLevel = 0;
			$('.v_s_rzrq').removeClass('red green');
			if (isNaN(data)) {
				$('.v_s_rzrq').text('--');
			} else {
				if (data <= -0.03) {
					starLevel = 1;
				} else if (data > -0.03 && data <= -0.015) {
					starLevel = 2;
				} else if (data > -0.015 && data <= 0) {
					starLevel = 3;
				} else if (data > 0 && data <= 0.005) {
					starLevel = 4;
				} else if (data > 0.005 && data <= 0.01) {
					starLevel = 5;
				} else if (data > 0.01 && data <= 0.02) {
					starLevel = 6;
				} else if (data > 0.02 && data <= 0.03) {
					starLevel = 7;
				} else if (data > 0.03 && data <= 0.04) {
					starLevel = 8;
				} else if (data > 0.04 && data <= 0.05) {
					starLevel = 9;
				} else if (data > 0.05) {
					starLevel = 10;
				}
				if (data > 0) {
					$('.v_d_rzrq').addClass('red');
				} else if (data < 0) {
					$('.v_d_rzrq').addClass('green');
				}
				$('.v_d_rzrq').text((data * 100).toFixed(2) + '%');
			}
			gradeClass = gradeClass + starLevel;

			$('.v_s_rzrq').attr('data-rating', starLevel);
			$('.v_s_rzrq').attr('class', function(i, cls) {
				return cls.replace(/star-level\d+/g, gradeClass);
			});
		},
		calcComScore: function(cls) {
			var self = this;
			var $progressbar = $('.' + cls + '_wrap').find('.progress-bar');
			var $score = $('.' + cls + '_wrap').find('.progress-score');
			var $explain = $('.' + cls + '_wrap').find('.level-star');

			var count = 0;
			var scoreTol = 0;
			$explain.each(function() {
				var dataRating = parseInt($(this).attr('data-rating'));
				scoreTol += dataRating;
				count++;
			});
			var avg = scoreTol / count;

			var color = 'ff6c00';
			if (avg < 4) {
				color = '1c9d52';
			} else if (avg < 6) {
				color = 'eecb25';
			} else if (avg < 8) {
				color = 'ff6c00';
			} else {
				color = 'e52e2e';
			}

			avg = avg.toFixed(1);
			$progressbar.css('background', color).width(parseInt(avg * 10) + '%');
			$score.text(avg).css('color', color).attr('data-group-score', avg);

			self.throttle(self.calcComChartScore, 1000)();
		},

		calcComChartScore: async function() {
			var tradingDate = await clientApi.getTradingDay();
			var today = await clientApi.serverTime();
			var serverHour = await clientApi.serverHour();
			if (today == tradingDate && serverHour < 0930) {
				renderComChart('--');
			} else {
				var scqrScore = $('.scqr_wrap').find('.progress-score').attr('data-group-score');
				var zqxyScore = $('.zqxy_wrap').find('.progress-score').attr('data-group-score');
				var zjdtScore = $('.zjdt_wrap').find('.progress-score').attr('data-group-score');

				scqrScore = parseFloat(scqrScore);
				zqxyScore = parseFloat(zqxyScore);
				zjdtScore = parseFloat(zjdtScore);

				var comScore = parseFloat((scqrScore + zqxyScore + zjdtScore) / 3).toFixed(1);
				comScore = isNaN(comScore) ? '--' : comScore;

				renderComChart(comScore);
			}
		},

		timer: null,
		throttle: function(fn, delay) {
			var self = this;
			return function() {
				var context = this,
					args = arguments;
				clearTimeout(self.timer);
				self.timer = setTimeout(function() {
					fn.apply(context, args);
				}, delay);
			};
		},
		events: function() {
			$('.section-item').hoverDelay({
				hoverDuring: 300,
				outDuring: 200,
				hoverEvent: function(dom) {
					var _width = $(document).width();
					var _left = $('.module-overall').offset().left;
					if (_width - _left < 500) {
						$('.level-panel').css('left', '-158px');
					} else {
						$('.level-panel').css('left', '0');
					}

					dom.find('.level-panel').show();
				},
				outEvent: function(dom) {
					dom.find('.level-panel').hide();
				}
			});
		}
	};

	module.exports = overallModule;
});